import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types';
//列表数据
export const columns: BasicColumn[] = [
  // 隐藏用户Id列
  // {
  //  title: '用户id',
  //  align: 'center',
  //  dataIndex: 'userId'
  // },
  {
    title: '订单号',
    align: 'center',
    dataIndex: 'code',
    width: 360, // 原宽度的 1/3 增量，假设原宽度约 270，增加到 360
  },
  // 添加下单人和被监护人列（移到订单号后面）
  {
    title: '下单人',
    align: 'center',
    dataIndex: 'userName',
  },
  {
    title: '被监护人',
    align: 'center',
    dataIndex: 'familyName',
  },
  // 添加下单时间和机构代码列
  {
    title: '下单时间',
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: '机构代码',
    align: 'center',
    dataIndex: 'sysOrgCode',
  },
  {
    title: '订单状态',
    align: 'center',
    dataIndex: 'status',
    customRender: ({ text }) => {
      return render.renderDict(text, 'nurse_order_status');
    },
  },
    // 添加是否审核显示列
  {
    title: '是否审核',
    align: 'center',
    dataIndex: 'isAuth',
    customRender: ({ text }) => {
      return text === 1 ? '是' : '否';
    },
  },
  {
    title: '总价',
    align: 'center',
    dataIndex: 'totalPrice',
  },
  {
    title: '商户订单号',
    align: 'center',
    dataIndex: 'outTradeNo',
    width: 240, // 增加 1/3 宽度
  },
  {
    title: '订单摘要',
    align: 'center',
    dataIndex: 'orderText',
    width: 360, // 增加 1/3 宽度
  },
  // 去掉微信标识显示列
  {
    title: '护工姓名',
    align: 'center',
    dataIndex: 'nurseName',
  },
  {
    title: '是否拆分订单',
    align: 'center',
    dataIndex: 'isapart',
    customRender: ({ text }) => {
      if (text === '1' || text === 1) return '是';
      if (text === '0' || text === 0) return '否';
      return text || '';
    }
  },
  {
    title: '价格参数',
    align: 'center',
    dataIndex: 'rate',
  },
  {
    title: '护工手机',
    align: 'center',
    dataIndex: 'nursephone',
  },
  {
    title: '护工身份证',
    align: 'center',
    dataIndex: 'nurseidcard',
    width: 200,
  },

];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '订单号',
    field: 'code',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: '下单人',
    field: 'userName',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: '订单状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'nurse_order_status',
      placeholder: '请选择订单状态',
      stringToNumber: false,
    },
    //colProps: {span: 6},
  },
  // 添加是否审核查询条件
  {
    label: '是否审核',
    field: 'isAuth',
    component: 'Select',
    componentProps: {
      placeholder: '请选择是否审核',
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
    //colProps: {span: 6},
  },
  {
    label: '商户订单号',
    field: 'outTradeNo',
    component: 'Input',
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '用户id',
    field: 'userId',
    component: 'Input',
  },
  {
    label: '订单号',
    field: 'code',
    component: 'Input',
  },
  {
    label: '订单状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'nurse_order_status',
      placeholder: '请选择订单状态',
      stringToNumber: false,
    },
  },
  {
    label: '总价',
    field: 'totalPrice',
    component: 'InputNumber',
    dynamicRules: ({ _model, _schema }) => {
          return [{ required: false }, { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' }];
     },
  },
  {
    label: '商户订单号',
    field: 'outTradeNo',
    component: 'Input',
  },
  {
    label: '订单摘要',
    field: 'orderText',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
//子表单数据
//子表表格配置
export const medicationOrderDetailColumns: JVxeColumn[] = [
    {
      title: '商品id',
      key: 'goodsId',
      type: JVxeTypes.input,
      width: '200px',
      placeholder: '请输入${title}',
      defaultValue: '',
    },
    {
      title: '购买数量',
      key: 'num',
      type: JVxeTypes.input,
      width: '200px',
      placeholder: '请输入${title}',
      defaultValue: '',
    },
    {
      title: '单价',
      key: 'price',
      type: JVxeTypes.inputNumber,
      width: '200px',
      placeholder: '请输入${title}',
      defaultValue: '',
    },
    {
      title: '总价',
      key: 'totalPrice',
      type: JVxeTypes.inputNumber,
      width: '200px',
      placeholder: '请输入${title}',
      defaultValue: '',
    },
    {
      title: '订单id',
      key: 'orderId',
      type: JVxeTypes.input,
      width: '200px',
      placeholder: '请输入${title}',
      defaultValue: '',
    },
    {
      title: '商品名称',
      key: 'goodsName',
      type: JVxeTypes.input,
      width: '200px',
      placeholder: '请输入${title}',
      defaultValue: '',
    },
  ]

// 高级查询数据
export const superQuerySchema = {
  userId: {title: '用户id',order: 0,view: 'text', type: 'string',},
  code: {title: '订单号',order: 1,view: 'text', type: 'string',},
  status: {title: '订单状态',order: 2,view: 'text', type: 'string',},
  totalPrice: {title: '总价',order: 3,view: 'number', type: 'number',},
  outTradeNo: {title: '商户订单号',order: 4,view: 'text', type: 'string',},
  orderText: {title: '订单摘要',order: 5,view: 'text', type: 'string',},
  userName: {title: '下单人',order: 6,view: 'text', type: 'string',},
  isAuth: {title: '是否审核',order: 7,view: 'select', type: 'number', dict: 'yn'},
  isapart: {title: '是否拆分订单',order: 8,view: 'radio', type: 'string',},
  rate: {title: '价格参数',order: 9,view: 'number', type: 'number',},
  nursephone: {title: '护工手机',order: 10,view: 'text', type: 'string',},
  nurseidcard: {title: '护工身份证',order: 11,view: 'text', type: 'string',},
  //子表高级查询
  medicationOrderDetail: {
    title: '药房订单详情',
    view: 'table',
    fields: {
        goodsId: {title: '商品id',order: 0,view: 'text', type: 'string',},
        num: {title: '购买数量',order: 1,view: 'text', type: 'string',},
        price: {title: '单价',order: 2,view: 'number', type: 'number',},
        totalPrice: {title: '总价',order: 3,view: 'number', type: 'number',},
        orderId: {title: '订单id',order: 4,view: 'text', type: 'string',},
        goodsName: {title: '商品名称',order: 5,view: 'text', type: 'string',},
    }
  },
};
